<script setup>
import { h, onMounted, ref, resolveDirective, withDirectives } from 'vue'
import {
  NAvatar,
  NButton,
  NEllipsis,
  NFlex,
  NForm,
  NFormItem,
  NImage,
  NInput,
  NPopconfirm, NSelect,
  NSwitch,
  NTag,
  useMessage
} from 'naive-ui'

import CommonPage from '@/components/page/CommonPage.vue'
import QueryBarItem from '@/components/query-bar/QueryBarItem.vue'
import CrudModal from '@/components/table/CrudModal.vue'
import CrudTable from '@/components/table/CrudTable.vue'
import TheIcon from '@/components/icon/TheIcon.vue'
import { getToken } from '@/utils'
import { renderIcon } from '@/utils'
import { useCRUD } from '@/composables'
import api from '@/api'
import {router} from "@/router";
const base_path = import.meta.env.VITE_BASE
import default_image from "@/assets/images/mz.jpg"

defineOptions({ name: '企业管理' })
const $table = ref(null)
const queryItems = ref({})
import { useRoute } from 'vue-router';
const route = useRoute();

const {
  modalVisible,
  modalTitle,
  modalLoading,
  handleSave,
  modalForm,
  modalFormRef,
  handleEdit,
  handleDelete,
  handleAdd,
} = useCRUD({
  name: '企业',
  initForm: {},
  doCreate: api.createCustomersFollowUser,//接口地址修改
  doUpdate: api.updateCustomers,//接口地址修改
  doDelete: api.deleteCustomers,//接口地址修改
  refresh: () => $table.value?.handlerefresh(),
})

const data = reactive({
  customer_level: [],
  token: getToken(),
  uploadAction: base_path+'api/customers/customers_post/file_user',
  onLevelData: [],
  selectValue:'',
  show_excel:false,
  show_info:false,
  c_type:[],
  c_status:[],
  fileList1: [],
  fileList2: [],
  fileList3: [],
  add_uid:1,
});





onMounted(() => {
  handleAdd()
})

//表单规则部分
const addAPIRules = {
  qymc: [
    {
      required: true,
      message: '请输入企业名称',
      trigger: ['input', 'blur'],
    },
  ],
  qysh: [
    {
      required: true,
      message: '请输入企业税号',
      trigger: ['input', 'blur'],
    },
  ],
  yh_no: [
    {
      required: true,
      message: '请输入银行卡号',
      trigger: ['input', 'blur'],
    },
  ],
  name: [
    {
      required: true,
      message: '请输入法人姓名',
      trigger: ['input', 'blur'],
    },
  ],
  yh_khh: [
    {
      required: true,
      message: '请输入开户行',
      trigger: ['input', 'blur'],
    },
  ],
  yh_phone: [
    {
      required: true,
      message: '请输入预留手机号',
      trigger: ['input', 'blur'],
    },
  ],
}

//上传头像
const message = useMessage();
function on_save(){

  api.createCustomersFollowUser(modalForm.value).then((res) => {
         if(res.code === 200) {
           router.push('/post3?price='+res.msg)
          }else{
            message.error(data.data)
          }
        })
}


</script>

<template>
  <!-- 业务页面 -->
  <CommonPage show-footer style="background: #1b3a7d;">
    <template #header>
        <n-page-header subtitle="/    企业贷款专家" style="color:#ffffff">
    <template #title>
      <a href="https://anyway.fm/" style="text-decoration: none; color: #ffffff">贷款额度查询</a>
    </template>
    <template #avatar>
      <n-avatar
        src="https://cdnimg103.lizhi.fm/user/2017/02/04/2583325032200238082_160x160.jpg"
      />
    </template>
  </n-page-header>
    </template>

      <NForm ref="modalFormRef"   :label-width="100" :model="modalForm"
             :rules="addAPIRules" :validate-on-rule-change="true" size="large">

            <n-divider dashed>
              企业贷款额度查询
            </n-divider>
            <NFormItem label="企业名称" path="qymc">
              <NInput v-model:value="modalForm.qymc" clearable placeholder="企业名称" />
            </NFormItem>
            <NFormItem label="企业税号" path="qysh">
              <NInput v-model:value="modalForm.qysh" clearable placeholder="企业税号" />
            </NFormItem>
            <NFormItem label="法人姓名" path="name">
              <NInput v-model:value="modalForm.name" clearable placeholder="法人姓名" />
            </NFormItem>
            <NFormItem label="银行卡号" path="yh_no">
              <NInput v-model:value="modalForm.yh_no" clearable placeholder="银行卡号" />
            </NFormItem>
            <NFormItem label="开户行" path="yh_khh">
              <NInput v-model:value="modalForm.yh_khh" clearable placeholder="开户行" />
            </NFormItem>
             <NFormItem label="预留手机号" path="yh_phone">
              <NInput v-model:value="modalForm.yh_phone" clearable placeholder="预留手机号" />
            </NFormItem>



        <div style="padding: 0 50px">
        <NButton size="large" style="margin: auto;width: 100%" type="primary" @click="on_save">
          <TheIcon icon="material-symbols:search" :size="24" class="mr-5"  />查询额度
        </NButton>
        </div>

      </NForm>

  </CommonPage>
</template>
